﻿using SafoverWpfFw;
using System;
using System.Globalization;
using Safover.Lidar.DataContract;

namespace Safover.LidarCollector.Converter
{
    public class LidarWorkModeToIsEnabledConverter : BaseValueConverter<LidarWorkModeToIsEnabledConverter>
    {
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return DoConvert(value, parameter);
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        private object DoConvert(object value, object parameter) 
        {
            LidarWorkMode current, param;

            if (parameter != null)
            {
                if (Enum.TryParse(value.ToString(), out current) && Enum.TryParse(parameter.ToString(), out param))
                {
                    return current == param;
                }
            }
            else if (Enum.TryParse(value.ToString(), out current))
            {
                if (current != LidarWorkMode.Multi)
                {
                    return true;
                }
            }

            return false;
        }
    }
}
